Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Conversation

@bm-w
Copy link

@bm-w bm-w commented Apr 2, 2025

Python supports “nested” assignments like x = y = 42. In that particular context the nested y = 42 assignment sort of acts like an expression, and the result is bound to the LHS of the first assignment: x = <result>. However, assignments are not generally considered expressions, and as such the TSSG definition does not create an output node for it, causing an error in the the stanza that deals with assignments:

0: Error executing statement edge @pattern.input -> @value.output at (1299, 3)
     src/stack-graphs.tsg:1299:3:
     1299 |   edge @pattern.input -> @value.output
          |   ^
     in stanza
     src/stack-graphs.tsg:1288:1:
     1288 | [
          | ^
     matching (assignment) node
     test/assignments.py:6:1:
     6 | y = z = 1337
       | ^
1: Evaluating edge sink
2: Undefined scoped variable [syntax node assignment (6, 5)].output

The fragment of the parsed Tree-sitter tree for such a nested assignment is:

(assignment
  left: (…)
  right: (assignment
    left: (…)
    right: (…)))

As of v0.23.5 of the Python grammar, the right field of an assignment indeed accepts another assignment (via _right_hand_side).

Simply creating an output node for an assignment fixes the issue. Copious testing reveals no negative side effects.

Copilot AI review requested due to automatic review settings April 2, 2025 14:25
@bm-w bm-w requested review from a team as code owners April 2, 2025 14:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the issue with nested assignments in Python by creating an output node for assignment expressions. The changes ensure that nested assignments like "y = z = 1337" are handled correctly, and they add tests to verify the fix.

Files not reviewed (1)
  • languages/tree-sitter-stack-graphs-python/src/stack-graphs.tsg: Language not supported

@CleanCut
Copy link
Contributor

CleanCut commented Sep 9, 2025

The github/stack-graphs repository is no longer being maintained. As per #502, I'm closing all issues and pull requests before archiving the repository.

@CleanCut CleanCut closed this Sep 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants